package com.ler.yrmall.member.controller;

import com.ler.yrmall.basic.Result;
import com.ler.yrmall.member.entity.MemberReceiveAddressEntity;
import com.ler.yrmall.member.service.MemberReceiveAddressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author Leron
 */
@RestController
@RequestMapping("/address")
public class MemberReceiveAddressController {

    @Resource
    private MemberReceiveAddressService memberReceiveAddressService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result<?> list() {
        return Result.ok(memberReceiveAddressService.memberAddressList());
    }


    /**
     * 信息
     */
    @RequestMapping("/getById/{id}")
    public Result<?> getById(@PathVariable("id") Long id) {
        MemberReceiveAddressEntity memberReceiveAddress = memberReceiveAddressService.getById(id);
        return Result.ok(memberReceiveAddress);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody MemberReceiveAddressEntity memberReceiveAddress) {
        memberReceiveAddressService.saveAddress(memberReceiveAddress);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody MemberReceiveAddressEntity memberReceiveAddress) {
        memberReceiveAddressService.updateAddress(memberReceiveAddress);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        memberReceiveAddressService.deleteAddress(id);
        return Result.ok();
    }

    @GetMapping("/default")
    public Result<?> defaultAddress() {
        return Result.ok(memberReceiveAddressService.defaultAddress());
    }

}
